<template>
  <div class="logistics-box">
    <div class="commitOrder-address">
      <span class='commitOrder-addPic'></span>
      <span class='commitOrder-addbox'>
        <div class="pb5">
          <span class="pr10">{{orderLinkMan}}</span>
          <span>{{orderLinkManPhone}}</span>
        </div>
        <div class="commitOrder-add">{{orderAddress}}</div>
      </span>
    </div>
    <div class="commitOrder-content">
      <ul class="commitOrder-ul">
        <li class="commitOrder-li clearfix" v-for='(item, index) in $store.state.order.selectedLoisticsList' :key='index'>
          <div class="fl p10">
            <img class="commitOrder-li-img" :src="item.goodsImg">
          </div>
          <div class="commitOrder-price-box">
            <div class="font-size-18">{{item.goodsName}}</div>
            <div class='color-price'>￥{{item.goodsPrice}}</div>
            <div class="pr10 text-center">x{{item.goodsCount}}</div>
          </div>
          <div v-show='index != $store.state.order.selectedLoisticsList.length - 1' class="clearfix commitOrder-hr-box">
            <div class="commitOrder-hr-none"></div>
            <div class="commitOrder-hr"></div>
          </div>
        </li>
      </ul>
    </div>
    <div class="commitOrder-total-box">
      <span class="pr10">共计{{totalNum}}件商品</span>
      <span>合计：</span>
      <span class="color-price font-size-18">{{totalPrice}}</span>
    </div>
    <div class="logistics-bottom clearfix">
      <div class="logistics-bottom-price">
        合计金额
        <span class="price-total-1"><span>￥</span>{{totalPrice}}</span>
      </div>
      <div class="logistics-bottom-btn">
        <button class="logistics-button" @click='commitAction'>提交订单</button>
      </div>
    </div>
  </div>
</template>

<script>
  import {mapGetters, mapMutations, mapActions} from 'vuex';
  import {commitOrder} from '@/controller'
  export default {
    name: 'commitOrder',
    data() {
      return {
        orderAddress: this.$route.query.rdd_company.companyLocation,
        orderLinkMan: this.$route.query.rdd_user.userName,
        orderLinkManPhone: this.$route.query.rdd_user.userPhone,
      }
    },
    created() {
    },
    mounted() {
    },
    components: {
    },

    computed: {
      ...mapGetters([
        'totalPrice',
        'totalNum'
        ])
    },

    methods: {
      async commitAction() {
        var orderInfo = {
          orderList:[],
          orderSum: this.totalPrice,
        };
        this.$store.state.order.selectedLoisticsList.forEach((item) => {
          orderInfo.orderList.push({
            goodsId: item.id, 
            goodsName: item.goodsName, 
            goodsPrice: item.goodsPrice, 
            goodsCount: item.goodsCount, 
            goodsSum: item.goodsPrice * item.goodsCount
          });
        });
        let req = {
          orderAddress: this.orderAddress,
          orderLinkMan: this.orderLinkMan,
          orderLinkManPhone: this.orderLinkManPhone,
          orderInfo: JSON.stringify(orderInfo),
        }
        
        const res = await commitOrder(req);
        if(res.code === 0) {
          this.$router.push({
            path:`/successOrder`
          })
        } else {
          this.$toast.center('提交订单失败');
        }
      }
    }
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
  .logistics-box {
    background: #f6f6f6;
    width: 100vw;
    height: 100vh;
    overflow: auto;
    box-sizing: border-box;
  }

  .commitOrder-address {
    background: #fff;
    border-radius: 6px;
    padding: 15px;
    margin: 4vw;
    position: relative;
  }

  .commitOrder-content {
    padding: 0vw 4vw;
  }

  .commitOrder-ul {
    background: #fff;
    border-radius: 6px;
  }

  .commitOrder-li {
    list-style: none;
    padding: 5px 5px 0 5px;
    box-sizing: border-box;
  }

  .commitOrder-li-img {
    display: inline-block;
    width: 60px;
    height: 60px;
    border-radius: 4px;
    background: #ccc;
    float: left;
  }

  .commitOrder-price-box {
    float: left; 
    width: calc(100% - 80px);
    padding-top: 15px;
  }

  .commitOrder-addbox {
    display: inline-block;
    width: calc(100% - 45px);
    margin-left: 40px;
  }

  .commitOrder-hr {
    width: calc(100% - 80px);
    height: 100%;
    background: #ccc;
    float: left;
  }

  .commitOrder-hr-none {
    float: left;
    width: 80px;
    height: 100%;
  }

  .pr10 {
    padding-right: 10px;
  }

  .pb5 {
    padding-bottom: 5px;
  }

  .commitOrder-hr-box {
    float: left;
    width: 100%;
    height: 1px;
  }

  .text-center {
    text-align: right;
  }

  .color-price {
    color: #f6661f;
  }

  .font-size-18 {
    font-size: 18px;
  }

  .p10 {
    padding: 10px;
  }

  .commitOrder-total-box {
    text-align: right;
    padding: 2vw 4vw;
    margin-bottom: 70px;
  }

  .commitOrder-add {
    width: 100%;
    height: auto;
  }
</style>
